package filmring

/*
The class defines all of the properties of a Movie.  A movie can have an activity feed or
recent activity on the movie.  It also contains the roles associated with the movie.
 */

class Movie {
    Director director //The director of the movie
    String title      //The Title of the movie
    Date releaseDate  //The release date(DVD/VHS) of the movie
   // String normalizedTitle


    static hasMany = [
            reviews:Review,   //List of reviews associated with the movie
            ratings:Rating,   //List of ratings associated with the movie
            roles:Role,
            activityFeed:ActivityFeedEvent
    ]

    static constraints = {releaseDate(nullable: true)
    }

    public String retrieveAvgRating(){
        if(ratings==null){
            return "Not Yet Rated"
        }
        int totalRatings = 0
        for(Rating rating : ratings){
            totalRatings+=rating.rating
        }
        if(ratings.size()==0){
            return "Not Yet Rated"
        }
        return "${(totalRatings*1.0)/ratings.size()}"
    }

    public String retrieveNumberRatings(){
        return (ratings==null)?"Not Yet Rated":"${ratings.size()}"
    }

}
